package geralItemPedido;

import org.nakedobjects.extended.Cardinality;
import org.nakedobjects.extended.CompositeAssociation;
import org.nakedobjects.extended.Entity;
import org.nakedobjects.extended.Way;
import org.nakedobjects.extended.CompositeAssociation.CompositeType;
import org.nakedobjects.object.AbstractNakedObject;
import org.nakedobjects.object.Title;
import org.nakedobjects.object.collection.ExtendedInternalCollection;
import org.nakedobjects.object.value.TextString;

@Entity
public class Endereco extends AbstractNakedObject {
	
	private TextString linha1 = new TextString();
	private TextString linha2 = new TextString();
	
	@CompositeAssociation(
			cardinality = Cardinality.ManyToMany, 
			compositeType = CompositeType.Physical, 
			fieldRelatedName = "enderecos", 
			relatedWith = Cliente.class, 
			way = Way.TwoWay 
			)
	private final ExtendedInternalCollection clientes = new ExtendedInternalCollection(
			"Clientes", Cliente.class, this);
	
	public ExtendedInternalCollection getClientes() {
		return clientes;
	}
	
	public TextString getLinha1() {
		return linha1;
	}
	
	public TextString getLinha2() {
		return linha2;
	}
	
	private final ExtendedInternalCollection notasfiscais = new ExtendedInternalCollection(
			"Notasfiscais", NotaFiscal.class, this);
	
	public ExtendedInternalCollection getNotasfiscais() {
		return notasfiscais;
	}
	
	public Title title() {
		return new Title(getLinha1().title().toString() + ", " + getLinha2().title().toString());
	}
}
